package filter

import (
	"github.com/beego/beego/v2/server/web/context"
	"kong-social-api/commons/base/controller"
	"kong-social-api/commons/global"
)

func AppidFilter(ctx *context.Context) {
	global.SugarLog.Infof("1: 拦截器APPID白名单 %s 进来了...", "AppidFilter")
	// 1: 获取头部信息的appid
	AppidArr := ctx.Request.Header["Appid"]
	if len(AppidArr) == 0 || len(AppidArr[0]) == 0 {
		ctx.Output.JSON(controller.Response{Code: 60001, Message: "不受信任的网站，非法请求!"}, true, true)
		return
	}

	// 2: 开始判断appid是不是在白名单中
	appid := AppidArr[0]
	exsit := ValidateAppid(appid)
	if !exsit {
		ctx.Output.JSON(controller.Response{Code: 60001, Message: "appid错误，非法请求!"}, true, true)
		return
	}
}
